{% extends "templates/base.html" %}

{% block title%}View Ride{% endblock %}

{% block main %}
	<h2>view ride</h2>
	<p> <!-- ride details--!>
			<td><strong>Date</strong> {{ ride.date }}<br />
			<strong>From</strong> <a href="/location?id={{ ride.rideoffer.source.key.id }}">{{ ride.rideoffer.source.get_addressname }}</a><br />
			<strong>To</strong> <a href="/location?id={{ ride.rideoffer.destination.key.id }}">{{ ride.rideoffer.destination.get_addressname }}</a><br />
			<strong>Seats </strong> {{ride.count_seats}} <br />
			<p />
			<strong>Owner</strong> <a href="/profile?user={{ ride.owner.key.id }}">{{ ride.rideoffer.owner.user.email }}</a><br />
			<p />

			<strong>Departs from </strong><a href="/location?id={{ ride.rideoffer.source.key.id }}">{{ ride.rideoffer.source.get_addressname }}</a><strong> at </strong>{{ ride.departure_time }} <br />
			<strong>Arrives at </strong><a href="/location?id={{ ride.rideoffer.destination.key.id }}">{{ ride.rideoffer.source.get_addressname }}</a><strong> at </strong> {{ ride.arrival_time }}<br />

			{% if ride.notes %}
				<strong>Notes</strong> {{ rideoffer.notes }}<br />
			{% endif %}
			<p />


			<form method="post">
			<h3>{{ride.count_emptyseats }} seat{% ifnotequal ride.count_emptyseats 1 %}s{% endifnotequal %} available
			{% if ride.count_emptyseats %}<!-- show the request button-->
				<input type="hidden" name="do_request_ride" value="True">
				<input class="button"  value="Request a Seat" type="submit"></h3>
			{% else %}
		        </h3>
			{% endif %}
			{% if not requestable %} <!-- show the instruction-->
				<strong>
					Your request for a seat on this ride has been recorded
					and you will be notified when it is approved
				</strong>
			{% endif %}
			</form>

	</p>

{% if has_passengers %}<!-- show passengers --!>
<p>
<hr />
<table>
	<h2>passengers</h2>
	<tr>
	<th>User</th>
	<th>Date</th>
	</tr>
	{% for seat in ride.seats %}
	  {% if seat.passenger %}
			<tr class="row-a">
				<td>
					<a href="/profile?id={{ seat.passenger.user.key.id }}">{{seat.passenger.user.email}}</a></td>
				</td>
				<td>
					{{seat.accepted}}
				</td>
			{% ifequal current_user ride.rideoffer.owner %} <!-- only show "assign seat" if user is owner --!>
				<td>
					 <a href="/ride?id={{ride.key.id}}&seat_id={{seat.key.id}}&action=RM">Remove User</a></td> <!--TODO-->
				</td>
				<td>
					 <a href="/ride?id={{ride.key.id}}&seat_id={{seat.key.id}}&action=DEL">Delete Seat</a></td> <!--TODO-->
				</td>
			{% endifequal %}
		  	</tr>
	  {% endif %}
	{% endfor %}
</table>
</p>
<!-- end if - show passengers --!>
{% endif %}


{% ifequal current_user ride.rideoffer.owner %}{% if ride.passengerrequests.count %} <!-- show passenger requests --!>
<hr />
	<p>
	<table>
	<h2>passenger requests</h2>
      	<tr>
		<th>User</th>
        <th>Date</th>
		</tr>

      	{% for prq in ride.passengerrequests %}
			<tr class="row-a">

			<td>
				 <a href="/profile?id={{ prq.owner.key.id }}">{{prq.owner.user.email}}</a></td>
			</td>
			{% ifequal current_user ride.rideoffer.owner %} <!-- only show "assign seat" if user is owner --!>
				<td>
					 <a href="/ride?id={{ride.key.id}}&prq_id={{prq.key.id}}&action=APRV">Approve Request</a></td>
				</td>
			{% endifequal %}
		  </tr>
		{% endfor %}
		</table>

	</p>
	<!-- end if show passenger requests --!>
	{% endif %}
{% endifequal %}


{% if lat_lng_src and lat_lng_des %}
	<p> <!-- Static Google Map -->
		<h2>map</h2>
		<img src="http://maps.google.com/staticmap?&size=400x400&markers={{lat_lng_src}},reds%7C{{lat_lng_des}},blued&key={{key}}"/>
	</p>
{% endif %}

{% endblock %}